package io.github.talelin.latticy.service.impl;

import io.github.talelin.latticy.mapper.StudentMapper;
import io.github.talelin.latticy.service.StudentService;
import io.github.talelin.latticy.dto.student.CreateOrUpdateStudentDTO;
import io.github.talelin.latticy.model.StudentDO;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;

/**
* @author vvboy
*/
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public boolean createStudent(CreateOrUpdateStudentDTO validator) {
        StudentDO student = new StudentDO();
        BeanUtils.copyProperties(validator, student);
        return studentMapper.insert(student) > 0;
    }


    @Override
    public boolean updateStudent(StudentDO student, CreateOrUpdateStudentDTO validator) {
        BeanUtils.copyProperties(validator, student);
        return studentMapper.updateById(student) > 0;
    }

    @Override
    public StudentDO getById(Integer id) {
        return studentMapper.selectById(id);
    }

    @Override
    public List<StudentDO> findAll() {
        return studentMapper.selectList(null);
    }

    @Override
    public boolean deleteById(Integer id) {
        return studentMapper.deleteById(id) > 0;
    }

}
